import os


def get_current_upload_list():
    result_list = []
    index = 0
    for root, dirs, files in os.walk('upload/'):
        for file in files:
            filename = 'upload/' + file
            result_list.append({
                'name': file,
                'path': filename,
                'index': index
            })
            index += 1

    return result_list


def delete_from_upload_list(index: int):
    upload_list = get_current_upload_list()
    if index >= len(upload_list):
        raise ValueError(f"Index {index} not in range.")

    file_to_delete = upload_list[index]['path']
    os.remove(file_to_delete)
